import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.bugbuff.sso.SSOApplication;
import com.bugbuff.sso.config.AliyunSMSConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@Slf4j
@SpringBootTest(classes = SSOApplication.class)
@RunWith(SpringRunner.class)
public class SendSms {
    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                "LTAI4G6iZZ4vnbLipnxmj3UH", "yaZx9L1Pi06B5nEG2hT3slN63kuqbo");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", "13023093497"); //目标手机号
        request.putQueryParameter("SignName", "合肥传智健康"); //签名名称
        request.putQueryParameter("TemplateCode", "SMS_177539224"); //短信模板code
        request.putQueryParameter("TemplateParam", "{\"code\":\"213312\"}");//模板中变量替换
        try {
            CommonResponse response = client.getCommonResponse(request);

            //{"Message":"OK","RequestId":"EC2D4C9A-0EAC-4213-BE45-CE6176E1DF23","BizId":"110903802851113360^0","Code":"OK"}
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    private AliyunSMSConfig aliyunSMSConfig;

    @Test
    public void testAli() {
        log.info("info: {}", aliyunSMSConfig);
        String signName = this.aliyunSMSConfig.getSignName();
        if (signName == null) {
            System.out.println(true);
        }
        System.out.println(signName);
    }

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Test
    public void testOther() {
        sqlSessionTemplate.selectOne("");
    }



    @Test
    public void testOther1() {
        System.out.println(StringUtils.equalsIgnoreCase("gender", "man"));
    }

    @Autowired
    private MongoTemplate mongoTemplate;


}
